import java.util.*;

public class FuncArgs {
    static public Scanner sc = new Scanner(System.in);

    static public int isYear(int year) {
        return (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? 1 : 0;
    }

    static public int countYearDays(int startYear, int endYear) {
        int days = 0;

        while (startYear < endYear) {
            days += 365 + isYear(startYear++);
        }

        return days;
    }

    static public int countMonthDays(int month, int year) {
        int days = 30 * (month  - 1) + month / 2;
        days += (month == 9 || month == 11) ? 1 : 0;
        return (month > 2) ? days - (2 - isYear(year)) : days;
    }

    // 公鸡5元一只，母鸡3元一只，小鸡1元三只，现在打算用100元买一百只鸡，列出所有可能的组合
    static public void buy() {
        int i, j, k;

        for (i = 0; i < 21; ++i) {
            for (j = 0; j < 34; ++j) {
                k = 100 - i - j;
                if (k % 3 == 0 && i * 5 + j * 3 + k / 3 == 100) {
                    System.out.printf("公鸡: %d, 母鸡: %d, 小鸡: %d\n",
                            i, j, k);
                }
            }
        }
    }

    // 已知1900年的一月一号是星期一，问今年有多少个黑色星期五，(每个月的13号是星期五即黑色星期五)
    static public void blackFri() {
        int startYear = 1900;
        int nowYear = 2017;
        int days = 0, i;

        System.out.printf("请输入计算年: ");
        nowYear = sc.nextInt();

        days = countYearDays(startYear, nowYear) + 13;

        for (i = 1; i < 13; ++i) {
            if ((days + countMonthDays(i, nowYear)) % 7 == 5) {
                System.out.printf("%d 年 %d 月 13号 是黑色星期五!\n", nowYear, i);
            }
        }
    }

    //检查日期合法性
    static public boolean checkDate(int year, int month, int day) {
        if (year <= 0 || year > 9999
                || month < 1 || month > 12
                || day < 1 || day > 31
                || ((month == 4 || month == 6 || month == 9 || month == 11)
                        && day > 30)
                || (month == 2 && day > 28 + isYear(year)))
            return false;
        return true;
    }

    // 某人从2000年1月1号开始过着三天打鱼两天晒网的生活，输入年月日，查询那一天此人是在打鱼还是在晒网
    static public void fish() {
        int startYear = 2000;
        int year = startYear, month = 1, day = 1;
        int i;

        while (true) {
            System.out.printf("请输入年(-1为返回主菜单): ");
            year = sc.nextInt();
            System.out.printf("请输入月(-1为返回主菜单): ");
            month = sc.nextInt();
            System.out.printf("请输入日(-1为返回主菜单): ");
            day = sc.nextInt();

            if (year == -1 || month == -1 || day == -1)
                break;
            if (!checkDate(year, month, day)) {
                System.out.printf("输入日期不合法!\n");
                break;
            }

            day = (day + countYearDays(startYear, year) + countMonthDays(month, year)) % 5;

            if (day == 4 || day == 0) {
                System.out.println("此人在晒网!");
            } else {
                System.out.println("此人在打鱼!");
            }
        }
    }

    static public void showTriangle(int border, int tType) {
        int i, s, c, r;

        for (i = 0, s = border * border; i < s; ++i) {
            r = i / border;
            c = i % border;

            if ((tType == 1 && c >= r)
                 || (tType == 2 && c <= r)
                 || (tType == 3 && c <= border - r - 1)
                 || (tType == 4 && c >= border - r - 1))
                System.out.printf(" * ");
            else
                System.out.printf("   ");

            if (c + 1 == border)
                System.out.println();
        }
    }

    // 输入边长打印直角三角形用一个循环
    static public void triangle() {
        System.out.printf("请输入边长: ");
        int b = sc.nextInt();

        int i, j, s;
        for (i = 0; i < b; ++i) {
            for (j = 0; j <= i; ++j) {
                System.out.printf(" * ");
            }
            System.out.println();
        }

        for (i = 0; i < b; ++i) {
            for (j = 0, s = b - i; j < s; ++j) {
                System.out.printf(" * ");
            }
            System.out.println();
        }

        for (i = 0; i < b; ++i) {
            for (j = 0; j < i; ++j) {
                System.out.printf("   ");
            }
            for (j = 0, s = b - i; j < s; ++j) {
                System.out.printf(" * ");
            }
            System.out.println();
        }

        for (i = 0; i < b; ++i) {
            for (j = 0, s = b - i - 1; j < s; ++j) {
                System.out.printf("   ");
            }
            for (j = 0; j <= i; ++j) {
                System.out.printf(" * ");
            }
            System.out.println();
        }

        System.out.println();

        showTriangle(b, 1);
        showTriangle(b, 2);
        showTriangle(b, 3);
        showTriangle(b, 4);
    }

    static public void main(String [] args) {
        int input;
        boolean quit = false;

        while (!quit) {
            System.out.println("==== 作业 ====");
            System.out.println("1. 买鸡!");
            System.out.println("2. 黑色星期五!");
            System.out.println("3. 打鱼晒网!");
            System.out.println("4. 直角三角形!");
            System.out.println("5. 退出");
            System.out.printf("请输入[1 - 5]: ");
            input = sc.nextInt();

            switch (input) {
                case 1:
                    buy();
                    break;
                case 2:
                    blackFri();
                    break;
                case 3:
                    fish();
                    break;
                case 4:
                    triangle();
                    break;
                case 5:
                    quit = true;
                    break;
                default:
                    break;
            }
        }
    }
}
